/* 引用发送请求的方法 */
import{getUrl}from "../../utils/url";
import { post } from "../../utils/util";
let _this;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    phone:'',
    dphone:''
  },
  ddinput(e){
    let name = e.currentTarget.dataset.name
    this.data[name] = e.detail.value
    this.setData({
      phone: this.data.phone,
      dphone: this.data.dphone
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    _this = this
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#6e42d3',
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
async authorLogin(e){
    if(this.data.phone == ''){
      wx.showToast({
        title: '请填写手机号',
        icon:'none'
      })
    }else{
      wx.showLoading({
        title: '授权中',
        task:true
      })
      let userInfo = e.detail.userInfo
      console.log(userInfo);   /* 
        avatarUrl:微信头像      dphone：短号  phone:手机号
        gender:  1是男生
      */
      userInfo.id = wx.getStorageSync("user").id
      console.log(userInfo.id);
      userInfo.phone = this.data.phone
      userInfo.dphone = this.data.dphone
      let users={};
       users.phone=userInfo.phone;
       users.dphone=userInfo.dphone;
       users.avatarUrl=userInfo.avatarUrl;
       users.gender=userInfo.gender;
       users.name=userInfo.nickName;
/*      wx.request({
       url: getUrl()+"/user/save",
       data:users,
     }).then(res=>{
       console.log(res);
     }) */
     wx.request({
       url: getUrl()+`/user/save`,
       data:users,
       success: function(res) {
        /*  console.log(res); */
        wx.setStorageSync('user', res.data);
        wx.switchTab({
          url: '../../pages/mine/mine',
        })
       }
     })
  }
    
  },
 
})